<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Simple Calendar with Selection</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: Simple Calendar with Selection</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><style>
.example {
	font-size:15px;
}

.example h4 {
	border: none;
	text-transform: none;
}

.example th {
	background: none;
	color: #000;
	text-transform: none;
	border: none;
}
</style>

<div class="intro">
<p>
This example demonstrates how to instantiate a simple Calendar, with an initial date setting of September 2011. The Calendar is preconfigured to show the previous and next month's dates.
</p>

<p>
Try clicking on the toggle buttons to change the initial settings for showing the previous and next months' dates. You can also select dates in the calendar and see selected date on the right, reported via a <code>selectionChange</code> event, and formatted using DataType utility.
</p>
</div>

<div class="example yui3-skin-sam">
    <!-- Load the YUI CSSButton CSS file from gallery to create simple and quick buttons -->
<link href="http://yui.yahooapis.com/gallery-2011.08.31-20-57/build/gallerycss-cssbutton/gallerycss-cssbutton.css" type="text/css" rel="stylesheet" />

<!-- Add an additional blue button style -->
<style>
.yui3-skin-sam .yui3-button-color-blue {
  color: #fff;
  background-image: -webkit-gradient(linear, left top, left bottom, from(#599bdc), to(#3476b7));
  background-image: -webkit-linear-gradient(top, #599bdc, #3476b7);
  background-image: -moz-linear-gradient(top, #599bdc, #3476b7);
  background-image: -ms-linear-gradient(top, #599bdc, #3476b7);
  background-image: -o-linear-gradient(top, #599bdc, #3476b7);
  background-image: linear-gradient(top, #599bdc, #3476b7);
  filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#599bdc', EndColorStr='#3476b7');
  background-color: #3476b7;
}
</style>

<div id="demo" class="yui3-skin-sam yui3-g">
  <div id="leftcolumn" class="yui3-u">
     <!-- Container for the calendar -->
     <div id="mycalendar"></div>
  </div>
  <div id="rightcolumn" class="yui3-u">
   <div id="links" style="padding-left:20px;">
      <!-- The buttons are created simply by assigning the correct CSS class -->
      <div id="togglePrevMonth" class="yui3-button yui3-button-color-blue">Toggle Previous Month's Dates</div><br>
      <div id="toggleNextMonth" class="yui3-button yui3-button-color-blue">Toggle Next Month's Dates</div><br>
      Selected date: <span id="selecteddate"></span>
   </div>
  </div>
</div>

<script type="text/javascript">
YUI().use('calendar', 'datatype-date',  function(Y) {
    
    // Create a new instance of calendar, placing it in 
    // #mycalendar container, setting its width to 340px,
    // the flags for showing previous and next month's 
    // dates in available empty cells to true, and setting 
    // the date to August 2011.           
    var calendar = new Y.Calendar({
      contentBox: "#mycalendar",
      width:'340px',
      showPrevMonth: true,
      showNextMonth: true,
      date: new Date(2011, 07, 01)}).render();
    
    // Get a reference to Y.DataType.Date
    var dtdate = Y.DataType.Date;

    // Listen to calendar's selectionChange event.
    calendar.on("selectionChange", function (ev) {

      // Get the date from the list of selected
      // dates returned with the event (since only
      // single selection is enabled by default,
      // we expect there to be only one date)
      var newDate = ev.newSelection[0];

      // Format the date and output it to a DOM
      // element.
      Y.one("#selecteddate").setContent(dtdate.format(newDate));
    });


    // When the 'Show Previous Month' link is clicked,
    // modify the showPrevMonth property to show or hide
    // previous month's dates
    Y.one("#togglePrevMonth").on('click', function (ev) {
      ev.preventDefault();
      calendar.set('showPrevMonth', !(calendar.get("showPrevMonth")));      
    });

    // When the 'Show Next Month' link is clicked,
    // modify the showNextMonth property to show or hide
    // next month's dates
    Y.one("#toggleNextMonth").on('click', function (ev) {
      ev.preventDefault();
      calendar.set('showNextMonth', !(calendar.get("showNextMonth")));      
    });
});
</script>

</div>

<h2>Complete Example Source</h2>

<pre class="code prettyprint">&lt;!-- Load the YUI CSSButton CSS file from gallery to create simple and quick buttons --&gt;
&lt;link href=&quot;http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;gallery-2011.08.31-20-57&#x2F;build&#x2F;gallerycss-cssbutton&#x2F;gallerycss-cssbutton.css&quot; type=&quot;text&#x2F;css&quot; rel=&quot;stylesheet&quot; &#x2F;&gt;

&lt;!-- Add an additional blue button style --&gt;
&lt;style&gt;
.yui3-skin-sam .yui3-button-color-blue {
  color: #fff;
  background-image: -webkit-gradient(linear, left top, left bottom, from(#599bdc), to(#3476b7));
  background-image: -webkit-linear-gradient(top, #599bdc, #3476b7);
  background-image: -moz-linear-gradient(top, #599bdc, #3476b7);
  background-image: -ms-linear-gradient(top, #599bdc, #3476b7);
  background-image: -o-linear-gradient(top, #599bdc, #3476b7);
  background-image: linear-gradient(top, #599bdc, #3476b7);
  filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=&#x27;#599bdc&#x27;, EndColorStr=&#x27;#3476b7&#x27;);
  background-color: #3476b7;
}
&lt;&#x2F;style&gt;

&lt;div id=&quot;demo&quot; class=&quot;yui3-skin-sam yui3-g&quot;&gt;
  &lt;div id=&quot;leftcolumn&quot; class=&quot;yui3-u&quot;&gt;
     &lt;!-- Container for the calendar --&gt;
     &lt;div id=&quot;mycalendar&quot;&gt;&lt;&#x2F;div&gt;
  &lt;&#x2F;div&gt;
  &lt;div id=&quot;rightcolumn&quot; class=&quot;yui3-u&quot;&gt;
   &lt;div id=&quot;links&quot; style=&quot;padding-left:20px;&quot;&gt;
      &lt;!-- The buttons are created simply by assigning the correct CSS class --&gt;
      &lt;div id=&quot;togglePrevMonth&quot; class=&quot;yui3-button yui3-button-color-blue&quot;&gt;Toggle Previous Month&#x27;s Dates&lt;&#x2F;div&gt;&lt;br&gt;
      &lt;div id=&quot;toggleNextMonth&quot; class=&quot;yui3-button yui3-button-color-blue&quot;&gt;Toggle Next Month&#x27;s Dates&lt;&#x2F;div&gt;&lt;br&gt;
      Selected date: &lt;span id=&quot;selecteddate&quot;&gt;&lt;&#x2F;span&gt;
   &lt;&#x2F;div&gt;
  &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;

&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
YUI().use(&#x27;calendar&#x27;, &#x27;datatype-date&#x27;,  function(Y) {
    
    &#x2F;&#x2F; Create a new instance of calendar, placing it in 
    &#x2F;&#x2F; #mycalendar container, setting its width to 340px,
    &#x2F;&#x2F; the flags for showing previous and next month&#x27;s 
    &#x2F;&#x2F; dates in available empty cells to true, and setting 
    &#x2F;&#x2F; the date to August 2011.           
    var calendar = new Y.Calendar({
      contentBox: &quot;#mycalendar&quot;,
      width:&#x27;340px&#x27;,
      showPrevMonth: true,
      showNextMonth: true,
      date: new Date(2011, 07, 01)}).render();
    
    &#x2F;&#x2F; Get a reference to Y.DataType.Date
    var dtdate = Y.DataType.Date;

    &#x2F;&#x2F; Listen to calendar&#x27;s selectionChange event.
    calendar.on(&quot;selectionChange&quot;, function (ev) {

      &#x2F;&#x2F; Get the date from the list of selected
      &#x2F;&#x2F; dates returned with the event (since only
      &#x2F;&#x2F; single selection is enabled by default,
      &#x2F;&#x2F; we expect there to be only one date)
      var newDate = ev.newSelection[0];

      &#x2F;&#x2F; Format the date and output it to a DOM
      &#x2F;&#x2F; element.
      Y.one(&quot;#selecteddate&quot;).setContent(dtdate.format(newDate));
    });


    &#x2F;&#x2F; When the &#x27;Show Previous Month&#x27; link is clicked,
    &#x2F;&#x2F; modify the showPrevMonth property to show or hide
    &#x2F;&#x2F; previous month&#x27;s dates
    Y.one(&quot;#togglePrevMonth&quot;).on(&#x27;click&#x27;, function (ev) {
      ev.preventDefault();
      calendar.set(&#x27;showPrevMonth&#x27;, !(calendar.get(&quot;showPrevMonth&quot;)));      
    });

    &#x2F;&#x2F; When the &#x27;Show Next Month&#x27; link is clicked,
    &#x2F;&#x2F; modify the showNextMonth property to show or hide
    &#x2F;&#x2F; next month&#x27;s dates
    Y.one(&quot;#toggleNextMonth&quot;).on(&#x27;click&#x27;, function (ev) {
      ev.preventDefault();
      calendar.set(&#x27;showNextMonth&#x27;, !(calendar.get(&quot;showNextMonth&quot;)));      
    });
});
&lt;&#x2F;script&gt;</pre>

</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="How to create a single-pane calendar with selectable dates">
                                        <a href="calendar-simple.html">Simple Calendar with Selection</a>
                                    </li>
                                
                            
                                
                                    <li data-description="How to create a multi-pane calendar with custom-rendered cells and multiple date selection.">
                                        <a href="calendar-multipane.html">Two-Pane Calendar with Custom Rendering and Multiple Selection</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            

            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
